
package branch.action;

import branch.BranchConnectionThread;
import branch.snapshot.ITransfer;

public class ErroneousTransferMoneyAction implements IBranchAction, ITransfer {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3678003934661998701L;
	
	private int amount;
	private int senderId;
	private int receiverId;
	
	public ErroneousTransferMoneyAction(int amount, int senderId, int receiverId) {
		//TODO: Raise error when negative
		if(amount > 0) {
			this.senderId = senderId;
			this.receiverId = receiverId;
			this.amount = amount;
		}

	}
	
	public String toString() {
		 return String.format("Money Erroneously Transfered (amount) %d from Branch %d to Branch %d",amount, senderId, receiverId);
	}

	@Override
	public void execute(BranchConnectionThread branchConnectionThread) {
		
		branchConnectionThread.getBranch().addAmount(amount);
		branchConnectionThread.getBranch().getBranchGUI().setTransactionReceived(branchConnectionThread.getDistantBranchDAO().getId(), amount);// TODO
		System.out.println(this);
		
	}

	@Override
	public int getAmount() {
		return this.amount;
	}

	@Override
	public int getSenderId() {
		return this.senderId;
	}

	@Override
	public int getReceiverId() {
		return this.receiverId;
	}

	
	
}
